
package com.jf.cloud.product.feign;

import com.jf.cloud.api.product.feign.SkuFeignClient;
import com.jf.cloud.common.product.vo.SkuAddrVO;
import com.jf.cloud.common.product.vo.SkuVO;
import com.jf.cloud.common.product.vo.SpuVO;
import com.jf.cloud.common.product.vo.app.SkuAppVO;
import com.jf.cloud.common.product.vo.search.SpuAdminVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.product.service.SkuService;
import com.jf.cloud.product.service.SpuService;
import com.jf.cloud.product.service.SupplierSpuUpdateLaterOperateService;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.Hidden;

import java.util.List;
import java.util.Map;

/**
 * @author zz
 * @date 2020/12/8
 */
@RestController
@Hidden
public class SkuFeignController implements SkuFeignClient {

    @Autowired
    private SkuService skuService;

    @Autowired
    private SpuService spuService;

    @Autowired
    private MapperFacade mapperFacade;
    @Autowired
    private SupplierSpuUpdateLaterOperateService supplierSpuUpdateLaterOperateService;


    @Override
    public ServerResponseEntity<SkuVO> getById(Long skuId) {
        return ServerResponseEntity.success(skuService.getSkuBySkuId(skuId));
    }

    @Override
    public ServerResponseEntity<List<SkuAppVO>> listBySpuId(Long spuId) {

        SpuVO spuDb = spuService.getBySpuId(spuId);
        SpuVO spuVO = mapperFacade.map(spuDb, SpuVO.class);
        List<SkuAppVO> skuList = skuService.getSpuDetailSkuInfo(spuVO);
        return ServerResponseEntity.success(skuList);
    }

    @Override
    public ServerResponseEntity<List<SkuVO>> listBySpuIds(List<Long> spuIds) {

        return ServerResponseEntity.success(skuService.listBySpuIds(spuIds));
    }

    @Override
    public ServerResponseEntity<List<SkuVO>> listSupplierBySpuIds(List<Long> spuIds, Long shopId) {
        return ServerResponseEntity.success(skuService.listSupplierBySpuIds(spuIds, shopId));
    }

    @Override
    public ServerResponseEntity<List<SkuAddrVO>> listSpuDetailByIds(List<Long> skuIds) {
        return ServerResponseEntity.success(skuService.listSpuDetailByIds(skuIds));
    }

    @Override
    public ServerResponseEntity<Long> getMinPriceFeeByIds(List<Long> skuIds) {
        return ServerResponseEntity.success(skuService.getMinPriceFeeByIds(skuIds));
    }

    @Override
    public ServerResponseEntity<Void> synCommissionSku(Long supplierSpuId) {
        skuService.synCommissionSku(supplierSpuId);
        return ServerResponseEntity.success() ;
    }

    @Override
    public ServerResponseEntity<Void> synMarketPrice(Long skuId, Long price) {
        supplierSpuUpdateLaterOperateService.synMarketPrice(skuId,price);
        return ServerResponseEntity.success() ;
    }

    @Override
    public ServerResponseEntity<Map<Long,Integer>> listConsignmentSku(Long spuId,Long supplierSpuId) {
        Map<Long, Integer> supplierSkuStock = skuService.getSupplierSkuStock(spuId,supplierSpuId);
        return ServerResponseEntity.success(supplierSkuStock);
    }

    @Override
    public ServerResponseEntity<List<SkuVO>> getByIds(List<Long> skuIds) {
        return ServerResponseEntity.success(skuService.getByIds(skuIds));
    }

    @Override
    public ServerResponseEntity<List<SpuAdminVO>> setSpuSku(List<SpuAdminVO> spuAdminVOS) {
        return ServerResponseEntity.success(skuService.setSpuSku(spuAdminVOS));
    }
}
